package com.tree.web;


import com.tree.entity.Grass;
import com.tree.service.GrassService;
import com.tree.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = "/grass")
public class GrassController {

    @Autowired
    private GrassService grassService;

    @RequestMapping(value = "/getlist")
    private String getList(ModelMap modelMap, HttpServletRequest request){

        //获取当前页数
        int rowIndex = HttpUtil.getInt(request,"rowIndex");
        List<Grass> list = new ArrayList<>();
        list = grassService.queryAll(rowIndex,10);
        modelMap.addAttribute("list",list);
        modelMap.addAttribute("rowIndex",rowIndex);
        return "grass/grasss";
    }
    @RequestMapping(value = "/show")
    private String show(ModelMap modelMap, HttpServletRequest request){
        //通过论文名获取论文
        Grass grass = grassService.query(HttpUtil.getString(request,"grassTerm"));
        modelMap.addAttribute("grass",grass);
        return "grass/grass";
    }
}
